﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Componnent.Common;

using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Domain.ViewModels.BasicSet;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(IBankSetService))]
    public class BankSetService : CoreServiceBase, IBankSetService
    {
        [Import]
        public IBankSetRepository BankSetRepository { get; set; }

        public IQueryable<BankSet> BankSets
        {
            get { return BankSetRepository.Entities; }
        }

        public OperationResult Insert(Domain.ViewModels.BasicSet.BankSet.BankSetModel model)
        {
            var entity = new BankSet
            {
                Yin_HDM_No = model.Yin_HDM_No != 0 ? model.Yin_HDM_No : null,
                Yin_HMC = model.Yin_HMC,
                Yin_HJC = model.Yin_HJC,
                CreateDT = DateTime.Now,
                Yin_HDZ = model.Yin_HDZ,
                Dian_H = model.Dian_H,
                Chuan_Z = model.Chuan_Z,
                Lian_XR = model.Lian_XR,
                ReviseDT = DateTime.Now

            };
            BankSetRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(Domain.ViewModels.BasicSet.BankSet.BankSetModel model)
        {
            var entity = new BankSet
            {
                Id = model.Id,
                Yin_HDM_No = model.Yin_HDM_No != 0 ? model.Yin_HDM_No : null,
                Yin_HMC = model.Yin_HMC,
                Yin_HJC = model.Yin_HJC,
                CreateDT = DateTime.Now,
                Yin_HDZ = model.Yin_HDZ,
                Dian_H = model.Dian_H,
                Chuan_Z = model.Chuan_Z,
                Lian_XR = model.Lian_XR,
                ReviseDT = DateTime.Now

            };
            BankSetRepository.Update(entity);
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public OperationResult Delete(int Id)
        {
            var model = BankSets.FirstOrDefault(t => t.Id == Id);
            model.IsDeleted = true;

            BankSetRepository.Update(model);
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
